home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / (A)TA / (A)TAP.ADF / Hacks / melt.c < prev    next >
C/C++ Source or Header  |  1987-02-03  |  5KB  |  160 lines

  1. /***********************************************************************\
  2. *                                                                       *
  3. *       Melt -- Yet another screen hack.  This is the direct            *
  4. *               result of playing with Tilt too late at night.          *
  5. *               Thank you Leo.                                          *
  6. *                                                                       *
  7. *                               Stephen Coy                             *
  8. *                               15407 Garden St. Apt. C                 *
  9. *                               Sumner, WA  98390                       *
  10. *                               uw-beaver!ssc-vax!coy                   *
  11. *                                                                       *
  12. *       This program may be freely distributed, modified and            *
  13. *       criticized.  Use it as you see fit.                             *
  14. *                                                                       *
  15. *       Note:   This compiles with Manx using 32-bit ints.  If          *
  16. *               you want 16-bit ints you should just have to            *
  17. *               clean up melt().                                        *
  18. *                                                                       *
  19. \***********************************************************************/
  20.  
  21. #include <exec/types.h>
  22. #include <intuition/intuition.h>
  23. #define DEPTH   2
  24.  
  25. extern void     *OpenLibrary(), *OpenWindow(), *OpenScreen(), *GetMsg();
  26.  
  27. struct NewScreen scrdef = {
  28.                 0, 0, 0, 0, DEPTH,
  29.                 0, 1,
  30.                 NULL,
  31.                 CUSTOMSCREEN,
  32.                 NULL,
  33.                 (UBYTE *) "Help me!",
  34.                 NULL, NULL
  35. };
  36.  
  37. struct NewWindow windef = {
  38.                 0, 30, 140, 10,
  39.                 -1, -1,
  40.                 CLOSEWINDOW,
  41.                 WINDOWCLOSE | WINDOWDRAG | WINDOWDEPTH | 
  42.                 SMART_REFRESH | ACTIVATE,
  43.                 NULL, NULL,
  44.                 (UBYTE *) "Melt",
  45.                 NULL, NULL,
  46.                 0, 0, 0, 0,
  47.                 WBENCHSCREEN
  48. };
  49.  
  50. struct Screen   *scr;
  51. struct Window   *win;
  52. struct TmpRas   tmpras;
  53. void            *IntuitionBase, *GfxBase;
  54.  
  55. main()
  56. {
  57.         struct Screen   *wb;
  58.         struct RastPort *rp;
  59.         struct BitMap   *wbm, *mbm;
  60.         long    x, y, n;
  61.         register int i;
  62.  
  63.         openstuff();
  64.  
  65.         wb = win->WScreen;
  66.         scrdef.LeftEdge  = wb->LeftEdge;
  67.         scrdef.TopEdge   = wb->TopEdge;
  68.         scrdef.Width     = wb->Width;
  69.         scrdef.Height    = wb->Height;
  70.         scrdef.ViewModes = wb->ViewPort.Modes;
  71.         if(!(scr = OpenScreen(&scrdef)))
  72.           die("Screen open failed!");
  73.         ScreenToBack(scr);
  74.  
  75.         rp = &scr->RastPort;
  76.         mbm = rp->BitMap;
  77.         wbm = win->WScreen->RastPort.BitMap;
  78.         BltBitMap(wbm, 0L, 0L, mbm, 0L, 0L,
  79.                   (long)scrdef.Width, (long)scrdef.Height,
  80.                   0xc0L, 0xffL, NULL);
  81.         ScreenToFront(scr);
  82.         melt(rp, mbm);
  83.         closestuff();
  84. }
  85.  
  86.  
  87. melt(rp, bitmap)
  88. struct RastPort *rp;
  89. struct BitMap   *bitmap;
  90. {
  91.         int     class;
  92.         struct  IntuiMessage    *message;
  93.         int     x, y,                   /* start positions              */
  94.                 dx, dy,                 /* offsets                      */
  95.                 u, v;                   /* size                         */
  96.         int     TempA[32];              /* temp buffer                  */
  97.         char    mask;                   /* bit-plane mask for blitter   */
  98.  
  99.         FOREVER {
  100.           message = (struct IntuiMessage *)GetMsg(win->UserPort);
  101.           if(message != (struct IntuiMessage *)NULL) {
  102.             class = message->Class;
  103.             ReplyMsg(message);
  104.             if(class == CLOSEWINDOW) {
  105.               return;
  106.             }
  107.           }
  108.           for(mask=1; mask<+(1<<DEPTH)-1; mask*=2) {
  109.             u = RangeRand(scr->Width - 3) + 1;
  110.             v = RangeRand(scr->Height - 3) + 1;
  111.             x = RangeRand(scr->Width - 1 - u) + 1;
  112.             y = RangeRand(scr->Height - 2 - v) + 1; 
  113.             dx = RangeRand(3) - 1;
  114.             dy = RangeRand(3);  /* also try dy = RangeRand(3) - 1;  */
  115.  
  116.             BltBitMap(bitmap, x, y,
  117.                       bitmap, x+dx, y+dy,
  118.                       u, v, 0x0c0, mask, TempA);
  119.           }     /* end of for mask */
  120.  
  121.         }     /* end of FOREVER */
  122. }     /* end of melt */
  123.  
  124. openstuff()
  125. {
  126.         if(!(IntuitionBase = OpenLibrary("intuition.library", 0L))) {
  127.           puts("Intuition missing.");
  128.           exit(100);
  129.         }
  130.  
  131.         if(!(GfxBase = OpenLibrary("graphics.library", 0L))) {
  132.           puts("Art shop clode.");
  133.           exit(100);
  134.         }
  135.  
  136.         if(!(win = OpenWindow(&windef))) {
  137.           puts("Window painted shut.");
  138.           closestuff();
  139.           exit(100);
  140.         }
  141. }
  142.  
  143. die(str)
  144. char    *str;
  145. {
  146.         puts(str);
  147.         closestuff();
  148.         exit(100);
  149. }
  150.  
  151. closestuff()
  152. {
  153.         if(tmpras.RasPtr) FreeRaster(tmpras.RasPtr, 320, 200);
  154.         if(scr)           CloseScreen(scr);
  155.         if(win)           CloseWindow(win);
  156.         if(GfxBase)       CloseLibrary(GfxBase);
  157.         if(IntuitionBase) CloseLibrary(IntuitionBase);
  158. }
  159.  
  160.